/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
bool solution(struct TreeNode* p, struct TreeNode* q) {
    if (!q && !p) {
        return true;
    }
    if (p && q == NULL) {
        return false;
    }
    if (q && p == NULL) {
        return false;
    }
    if (p->val != q->val) {
        return false;
    }
    return solution(p->left, q->right) && solution(p->right, q->left);

}

bool isSymmetric(struct TreeNode* root) {
    if (!root) {
        return true;
    }
    if (!root->left && !root->right) {
        return true;
    }
    if (!(root->left && root->right)) {
        return false;
    }
    if (root->left->val != root->right->val) {
        return false;
    }
    return solution(root->left, root->right);
}